package com.nageoffer.shortlink.admin.toolkit;

import java.util.Random;

/**
 * 随机id生成器
 */
public final class RandomGenerator {
    private static final String ALPHA_NUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    private static final Random RANDOM = new Random();

    public static String generateRandomAlphanumeric(int length) {
        if (length <= 0) {
            throw new IllegalArgumentException("Length must be positive");
        }

        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int index = RANDOM.nextInt(ALPHA_NUMERIC.length());
            sb.append(ALPHA_NUMERIC.charAt(index));
        }
        return sb.toString();
    }

    /**
     * Generate a 6-character random alphanumeric string
     * @return 6-character random string
     */
    public static String generate6DigitAlphanumeric() {
        return generateRandomAlphanumeric(6);
    }
}
